import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xin_nuo_pda/utils/MyDateUtils.dart';
import 'package:xin_nuo_pda/utils/string_extension.dart';
import 'package:xin_nuo_pda/values/colors.dart';
import 'package:xin_nuo_pda/views/TextView.dart';
import 'package:xin_nuo_pda/views/edittext/ClearBorderEditText.dart';
import 'package:xin_nuo_pda/views/edittext/TitleEditText.dart';

import 'EquipmentAskRepairController.dart';

class EquipmentAskRepairPage extends StatelessWidget {
  final controller = Get.put(EquipmentAskRepairController());
  final state = Get.find<EquipmentAskRepairController>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("生产报修"),
        actions: [
          Align(
            alignment: Alignment.centerRight,
            child: Container(
              height: 36,
              padding: EdgeInsets.fromLTRB(4, 0, 4, 0),
              margin: EdgeInsets.only(right: 8),
              child: OutlinedButton(
                style: OutlinedButton.styleFrom(
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(8.0),
                  ),
                  side: BorderSide(width: 1, color: Colors.white),
                ),
                onPressed: () {
                  controller.submit();
                },
                child: Text(
                  "提交",
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
          )
        ],
      ),
      body: SingleChildScrollView(
        child: Container(
          child: Column(
            children: [
              TitleEditText(
                "设备ID*:",
                "请扫描设备ID",
                (value) {
                  state.eqpID = value;
                  state.focusNode1.unfocus();
                  FocusScope.of(Get.context!).requestFocus(state.focusNode2);
                  controller.getEqpInfo();
                },
                focusNode: state.focusNode1,
                controller: TextEditingController(text: state.eqpID),
              ),
              GetBuilder<EquipmentAskRepairController>(
                  builder: (logic) => TextView("设备型号:", state.eqpInfoEntity?.eQUIPMENT?.mODEL ?? ''),id: state.eqpInfoId,),
              TitleEditText(
                "批次ID:",
                "请扫描批次ID",
                (value) {
                  state.lotID = value;
                },
                focusNode: state.focusNode2,
                controller: TextEditingController(text: state.lotID),
              ),
              Container(
                margin: EdgeInsets.all(8),
                alignment: Alignment.centerLeft,
                child: Text(
                  "报修信息",
                  style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
                ),
              ),
              Container(
                  padding: EdgeInsets.fromLTRB(12, 8, 12, 8),
                  color: Colors.white,
                  child: Row(
                    children: [
                      Expanded(
                        child: Text(
                          "故障描述*:",
                          style: TextStyle(color: theme_blue.toColor()),
                        ),
                        flex: 3,
                      ),
                      Expanded(
                          flex: 7,
                          child: ClearBorderEditText(
                            "请填写故障描述",
                            (value) {},
                            controller: state.descController,
                          ))
                    ],
                  )),
              SizedBox(
                height: 1,
              ),
              TitleEditText(
                "操作员:",
                "请输入操作员",
                    (value) {
                },
                isScan: false,
                controller: state.userController,
              ),
              SizedBox(
                height: 1,
              ),
              GetBuilder<EquipmentAskRepairController>(
                builder: (logic) => Container(
                    padding: EdgeInsets.fromLTRB(12, 8, 12, 8),
                    color: Colors.white,
                    child: Row(
                      children: [
                        Expanded(
                          child: Text(
                            "故障发生时间*:",
                            style: TextStyle(color: theme_blue.toColor()),
                          ),
                          flex: 3,
                        ),
                        Expanded(
                            flex: 7,
                            child: Material(
                              child: Ink(
                                child: InkWell(
                                  onTap: () {
                                    MyDateUtils.showDateTime(context, (date) {
                                      controller.updateSelectDate(date);
                                    }, currentTime: state.selectDate);
                                  },
                                  child: Container(
                                    alignment: Alignment.centerLeft,
                                    padding: EdgeInsets.only(left: 8),
                                    height: 36,
                                    decoration: BoxDecoration(
                                        border: new Border.all(
                                            width: 1.0, color: Colors.grey),
                                        borderRadius: BorderRadius.all(
                                            Radius.circular(8))),
                                    child: Row(
                                      children: [
                                        Expanded(
                                            child: Text(
                                              state.selectDate.year.toString() +
                                                  "年" +
                                                  state.selectDate.month
                                                      .toString() +
                                                  "月" +
                                                  state.selectDate.day
                                                      .toString() +
                                                  "日" +
                                                  state.selectDate.hour
                                                      .toString() +
                                                  '时' +
                                                  state.selectDate.minute
                                                      .toString() +
                                                  '分',
                                            ),
                                            flex: 1),
                                        Icon(
                                          Icons.arrow_forward_ios,
                                          size: 16,
                                        ),
                                        SizedBox(
                                          width: 4,
                                        )
                                      ],
                                    ),
                                  ),
                                ),
                              ),
                            ))
                      ],
                    )),
                id: state.dateChooseId,
              ),
              SizedBox(
                height: 1,
              ),
              Container(
                  padding: EdgeInsets.fromLTRB(12, 8, 12, 8),
                  color: Colors.white,
                  child: Row(
                    children: [
                      Expanded(
                        child: Text(
                          "备注:",
                          style: TextStyle(color: theme_blue.toColor()),
                        ),
                        flex: 3,
                      ),
                      Expanded(
                          flex: 7,
                          child: ClearBorderEditText(
                            "请填写备注",
                            (value) {},
                            controller: state.contentController,
                          ))
                    ],
                  ))
            ],
          ),
        ),
      ),
    );
  }
}
